<?php

class dbConnect{
	private $server = "localhost";
	private $user = "root";
	private $password = "xl19821021";
	private $database = "scmetrics";
	private $connect;

	function __construct(){
		$this->coninternal($this->server, $this->user, $this->password, $this->database);
	}

	private function coninternal($hostname, $username, $pass, $db_name, $pconnect = 0) 
	{
		$func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';
		
		$this->connect = @$func($hostname, $username, $pass) or die("Mysql_Error : .mysql_error(). Mysql Error Num : .mysql_errno().");		
		@mysql_select_db($db_name, $this->connect) or die("Mysql_Error : .mysql_error(). Mysql Error Num : .mysql_errno().");
	}
	
	function execSql($sql){
		mysql_db_query($this->database, $sql, $this->connect);
	}
	
	public function query_error($sql)
	{
		global $connect;
		$result = mysql_query($sql, $connect) or die("Mysql_Query : .$sql. Mysql_Error : .mysql_error(). Mysql Error Num : .mysql_errno().");
		
		return $result;
	} 

	public function fetch_array($sql, $result_type = MYSQL_ASSOC, $records = "one")
	{
		$result = mysql_db_query($this->database, $sql, $this->connect);
		
		if ($records == "one") {
			return @mysql_fetch_array($result, $result_type);
		}
		
		for ($i=0; num_rows($result); $i++)
		{
			$info[$i] = @mysql_fetch_array($result, $result_type);
		}
		
		free_result($result);
		
		return $info;
	} 

	public function error_msg($msg, $url= "")
	{
		global $connect;

		if($connect) {
			mysql_close($connect);
		}

		switch ($url)
		{
			case "":
				$url = "history.go(-1)";
				break;
			case "close":
				$url = "window.close()";
				break;
			default:
				$url = "document.location.href = '$url'";
				break;  
		}
		
		if (!empty($msg)) {
			echo "<script language='javascript'>alert('$str'); $url;</script>";
		}
		else{
			echo "<script language='javascript'>$url;</script>";
		}
		exit;
	}
		
	function __destruct(){
	}
}

?>